namespace SimpleWebServices.Web.UI.Html.Elements
{
    using System;
    using System.Xml;
    using System.Xml.Serialization;

    public abstract class Cell : CellAlignment, IXmlSerializable
    {
        public string Abbreviated
        {
            get;
            set;
        }

        public string Axis
        {
            get;
            set;
        }

        public string ColumnSpan
        {
            get;
            set;
        }

        public string RowSpan
        {
            get;
            set;
        }

        public override void ReadXml(XmlReader reader)
        {
            string value = reader.GetAttribute("abbr");
            if (!string.IsNullOrEmpty(value))
            {
                this.Abbreviated = value;
            }

            value = reader.GetAttribute("axis");
            if (!string.IsNullOrEmpty(value))
            {
                this.Axis = value;
            }

            value = reader.GetAttribute("colspan");
            if (!string.IsNullOrEmpty(value))
            {
                this.ColumnSpan = value;
            }

            value = reader.GetAttribute("rowspan");
            if (!string.IsNullOrEmpty(value))
            {
                this.RowSpan = value;
            }

            base.ReadXml(reader);
        }

        public override void WriteXml(XmlWriter writer)
        {
            if (!string.IsNullOrEmpty(this.Abbreviated))
            {
                writer.WriteAttributeString("abbr", this.Abbreviated);
            }

            if (!string.IsNullOrEmpty(this.Axis))
            {
                writer.WriteAttributeString("axis", this.Axis);
            }

            if (!string.IsNullOrEmpty(this.ColumnSpan))
            {
                writer.WriteAttributeString("colspan", this.ColumnSpan);
            }

            if (!string.IsNullOrEmpty(this.RowSpan))
            {
                writer.WriteAttributeString("rowspan", this.RowSpan);
            }

            base.WriteXml(writer);
        }
    }
}